<?php
namespace Admin\Model;
use Think\Model;
/**
 * 配置模型
 */

class MenuModel extends Model {
    protected $_validate = array(
        array('url', 'require', 'URL不能为空', self::EXISTS_VALIDATE, 'regex', self::MODEL_BOTH),
        array('url', '', 'URL已经存在', self::VALUE_VALIDATE, 'unique', self::MODEL_BOTH),
        array('title', 'require', '名称不能为空', self::MUST_VALIDATE , 'regex', self::MODEL_BOTH),
    );
    
    /*===============首页菜单权限读取================*/
    public function getMenuList($where){
    	$menu_list = $this->where($where.' pid=0')->order('sort asc,id asc')->select();
    	foreach ($menu_list as $key=>$val){
    		$menu_list[$key]['cat']	= $this->getCatList($val['id'],$where);
    	}
    	return $menu_list;
    }
    
    public function getCatList($pid,$where){
    	$cat_list = $this->where("$where pid=$pid")->order('sort asc,id asc')->select();
    	foreach ($cat_list as $key=>$val){
    		$cat_list[$key]['u_url']	= U("$val[url]");
    		$cat_list[$key]['two_cat']	= $this->getTwoCatList($val['id'],$where);
    	}
    	return $cat_list;
    }
    
    public function getTwoCatList($pid,$where){
    	$cat_list = $this->where("$where pid=$pid")->order('sort asc,id asc')->select();
    	return $cat_list;
    }
    /*===============首页菜单权限读取================*/
}
?>
